<template>
  <div class="category-list">
    <el-skeleton v-if="loading" :count="8" animated>
      <template #template>
        <div class="skeleton-category">
          <el-skeleton-item variant="image" style="width: 100%; height: 140px; border-radius: 8px;" />
          <el-skeleton-item variant="h3" style="width: 60%; margin-top: 10px" />
        </div>
      </template>
    </el-skeleton>
    
    <div v-else class="category-grid">
      <el-empty v-if="!categories || categories.length === 0" description="暂无分类" />
      
      <router-link 
        v-for="category in categories" 
        :key="category.id" 
        :to="`/courses?category=${category.id}`"
        class="category-card"
      >
        <div class="category-icon">
          <el-icon size="32"><component :is="getCategoryIcon(category.name)" /></el-icon>
        </div>
        <h3 class="category-name">{{ category.name }}</h3>
        <p class="category-description">{{ category.description || '暂无描述' }}</p>
      </router-link>
    </div>
  </div>
</template>

<script setup>
import { 
  Monitor, 
  DataAnalysis,
  Cpu,
  Link, 
  Iphone,
  DataLine,
  CloudComputer,
  Lock,
  Setting,
  Management
} from '@element-plus/icons-vue'

// Props
const props = defineProps({
  categories: {
    type: Array,
    default: () => []
  },
  loading: {
    type: Boolean,
    default: false
  }
})

// Map category names to icons
const getCategoryIcon = (name) => {
  const iconMap = {
    '计算机科学': 'Monitor',
    '数据科学': 'DataAnalysis',
    '人工智能': 'Cpu',
    'Web开发': 'Link',
    '移动开发': 'Iphone',
    '数据库': 'DataLine',
    '云计算': 'CloudComputer',
    '网络安全': 'Lock',
    '运维开发': 'Setting',
    '项目管理': 'Management'
  }
  
  // Return appropriate icon or default to Monitor
  return iconMap[name] || 'Monitor'
}
</script>

<style lang="scss" scoped>
.category-list {
  width: 100%;
}

.skeleton-category {
  width: 100%;
  max-width: 280px;
  padding: 20px;
  margin-bottom: 20px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
}

.category-card {
  background-color: var(--el-bg-color);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  transition: transform 0.3s, box-shadow 0.3s;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  text-decoration: none;
  color: var(--el-text-color-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  
  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    background-color: var(--el-color-primary-light-9);
    
    .category-icon {
      background-color: var(--el-color-primary);
      color: white;
    }
  }
  
  .category-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--el-color-primary-light-8);
    color: var(--el-color-primary);
    margin-bottom: 16px;
    transition: background-color 0.3s, color 0.3s;
  }
  
  .category-name {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px;
  }
  
  .category-description {
    font-size: 14px;
    color: var(--el-text-color-secondary);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style> 